<?php

namespace App\Kuafu\Wechat\Service\Message;

use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\Wechat\Enum\CodeEnum;
use App\Kuafu\Wechat\Service\WechatCallbackBaseService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;


/**
 * Class WechatMessage
 */
class WechatMessage extends WechatCallbackBaseService
{
    private string $passivitySendMsg = '';

    public function __construct(array $postObj)
    {
        parent::__construct($postObj);

        Log::channel('wechat')->info('receive wechat text data', $postObj);
    }


    public function handle()
    {
        // 处理回复消息
        $this->dealText();
        // 处理被动回复消息
        $this->passivitySendText($this->passivitySendMsg);
    }

    /**
     */
    public function dealText()
    {
        $content = $this->postData['Content'];

        if (strpos($content, '加盟') !== false ||
            strpos($content, '咨询') !== false ||
            strpos($content, '合作') !== false
        ) {
//            $content = CodeEnum::APPLET_EVENT_CLICK_US_CONTENT;

            $content = '可以扫下方二维码，领加盟资料↓';
            $this->sendText($content);

            $mediaId = 'etSbjkOLMJizBQB2Tgc8cpZPTTSTAxtN82rwgtw0u_lwwhOs6OXdh6aNe3PLIPg1';
            $this->sendImage($mediaId);


        } else {
            $content = '嗨你来啦!！我们家的小炸串吃的可还解馋？!
夸父炸串好吃，更值得加盟，点击这里，立刻获得加盟信息
<a data-miniprogram-appid="wx1913b646f245c2d3" data-miniprogram-path="pages/card/card?scene=cardId=407" data-miniprogram-nickname="夸父炸串加盟" data-miniprogram-type="text" href=" ">点击了解加盟信息</a>
';
            $this->sendText($content);

        }

//        $content = '可以扫下方二维码，领加盟资料↓';
//        $this->sendText($content);
//
//        $mediaId = 'etSbjkOLMJizBQB2Tgc8chQ83bQuqu9mySlepCswgiQm52-vHwqRBjaLDg0JR69_';
//        $this->sendImage($mediaId);
//        $this->passivitySendMsg = $content;

    }

}
